<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>添加部落</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <script src="/scripts/jquery.min.js"></script>
    <script src="/scripts/boot.js" type="text/javascript"></script>
    <script src="/scripts/miniui/miniui.js"></script>

    <style type="text/css">
        html, body {
            font-size: 12px;
            padding: 0;
            margin: 0;
            border: 0;
            height: 100%;
            overflow: hidden;
        }
    </style>
</head>
<body>

  <form id="form1" name="form1" method="post" action='/tribeRoute/imageUpload' enctype="multipart/form-data" >
    <input name="id" class="mini-hidden" />
    <div style="padding-left:11px;padding-bottom:5px; margin-top: 50px">
        <table style="table-layout:fixed; margin: 0 auto;text-align: center;">
            <tr>
                <td style="width:60px;">创建人：</td>
                <td >
                    <input id="creater" class="mini-buttonedit" onbuttonclick="onButtonEdit" style="width:155px; margin-right: 20px;" name="createrId" textName="createrName" allowInput="false" required="true"/>
                </td>
                <td style="width:60px;">部落名称：</td>
                <td >
                    <input id="name" name="name" class="mini-textbox" style="width:155px;" type="text" required="true" />
                </td>
            </tr>
            <tr>
                <td style="width:60px;">部落分类：</td>
                <td >
                    <input name="category" class="mini-combobox" style="width:155px; margin-right: 20px;" data="tribeCategory" valueField="text" textField="text" value="其他" type="text"/>
                </td>
                <td style="width:60px;">部落规模：</td>
                <td >
                    <input name="capacity" class="mini-textbox" style="width:155px;" value=2000 type="number"/>
                </td>
            </tr>
            <tr>
                <td style="width:60px;">是否公开：</td>
                <td >
                    <input name="isPublic" class="mini-combobox" style="width:155px; margin-right: 20px;" data="tribeIsPublic" value="1" type="text"/>
                </td>
                <td style="width:60px;">部落状态：</td>
                <td >
                    <input name="status" class="mini-combobox" data="tribeStatus" value="1" style="width:155px;" type="text"/>
                </td>
            </tr>
            <tr>
                <td style="width:60px;">认证方式：</td>
                <td >
                    <input name="verify" class="mini-combobox" style="width:155px; margin-right: 20px;" onvaluechanged="verifyValueChanged" data="tribeVerify"  value=1 type="number"/>
                </td>
                <td style="width:60px;">付费金额：</td>
                <td >
                    <input id="verifyCost" name="verifyCost" class="mini-textbox" style="width:155px;" type="number" allowInput="false" required="false"/>
                </td>
            </tr>
            <tr>
                <td style="width:60px;">推广分成：</td>
                <td >
                    <input name="generalize" class="mini-combobox" style="width:155px; margin-right: 20px;" textField="text" valueField="id" data="tribeGeneralize" value=0 type="number"/>
                </td>
                <td style="width:60px;">部落图像：</td>
                <td >
                    <input id="image" name="image" type="file" style="width:155px;" required="true"/>
                </td>
            </tr>
            <tr>

            <td >部落公告：</td>
            <td colspan="3">
                <input name="introduction" class="mini-textarea" style="width:400px;" />
            </td>
            </tr>
        </table>
    </div>
    <div style="text-align:center;padding:10px;">
        <!--<input type='submit' style="width:60px;margin-right:20px;" value='提交'/>-->
        <a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">确定</a>
        <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>
    </div>
</form>
<script type="text/javascript">
  var tribeStatus = [{ id: -1, text: '删除' }, { id: 0, text: '锁定'},{ id: 1, text: '正常'}];
  var tribeIsPublic = [{ id: 0, text: '私有' }, { id: 1, text: '公开'}];
  var tribeVerify = [{ id: 1, text: '无需验证' }, { id: 2, text: '需要验证'},{ id: 3, text: '付费加入'},{ id: 4, text: '禁止加入'}];
  var tribeGeneralize = [{ id: 0, text: '关闭' }, { id: 1 ,text: '开启'}];
  var tribeCategory = JSON.parse('<%- tribeCategory %>');
  mini.parse();
  var form = new mini.Form("form1");
  function verifyValueChanged(e) {
    var verfyCostObj = mini.get("verifyCost");
    if (e.value !=3 ) {
      verfyCostObj.setValue(undefined);
      verfyCostObj.allowInput = false;
      verfyCostObj.required = false;
    } else {
      verfyCostObj.allowInput = true;
      verfyCostObj.required = true;
    }
  }
  function SaveData() {
    var form = new mini.Form("#form1");
//    var data = form.getData();      //获取表单多个控件的数据
    form.validate();
    var verifyCost = mini.get('verifyCost').value;
    if (verifyCost.length > 0) {
      if(isNaN(verifyCost)){
        alert('付费金额，请输入数字！');
        return;
      }
    }
    var image = document.getElementById("image").value;
    if (image.length < 1){
      alert('请选择部落头像!');
      return;
    }
    var name = mini.get('name').value;
    $.ajax({
        url: "/tribeRoute/checkTribeNameIsUsable",
        type: 'post',
        data: {name:name},
        cache: false,
        success: function (result) {
//          console.log(result);
          if (result == 0){
            alert('部落名称，已经被占用！');
            return;
          } else if (result == 1) {
            //部落状态正常的没有重名
            document.form1.submit();
          } else {
//            console.log(result);
            alert('无法验证部落名称，请刷新页面！');
            return;
          }
        },
        error: function (error) {
          console.log(error)
        }
    });
  }

  ////////////////////
  //标准方法接口定义
  function SetData(data) {
  }

  function GetData() {
    var o = form.getData();
    return o;
  }

  function CloseWindow(action) {
    if (action == "close" && form.isChanged()) {
      if (confirm("数据被修改了，是否先保存？")) {
        return false;
      }
    }
    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
    else window.close();
  }
  function onButtonEdit(e) {
//    console.log(e)
    var btnEdit = mini.get('creater');
            mini.open({
              url: "/tribeRoute/tribeMGEditSelectCreater",
              title: "选择用户", width: 600, height: 400,
              ondestroy: function (action) {
                //if (action == "close") return false;
                if (action == "ok") {
                  var iframe = this.getIFrameEl();
                  var data = iframe.contentWindow.GetData();
                  data = mini.clone(data);    //必须
//          console.log(data)
                  if (data) {
                    btnEdit.setText(data.nickName);
                    btnEdit.setValue(data.objectId);
          }
        }
      }
    });

  }

  function onOk(e) {
    SaveData();
  }

  function onCancel(e) {
    CloseWindow("cancel");
  }

</script>
</body>
</html>
